//
// Created by mio on 25-5-12.
//

#ifndef LOGINWGT_H
#define LOGINWGT_H

#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QTcpSocket>

#include "../tool/define.h"

class LoginWgt : public QWidget
{
    Q_OBJECT
public:
    explicit LoginWgt(QWidget *parent = nullptr);

signals:
    void sig_logined(const std::string ip, uint16_t port);

protected slots:
    void ReadData();
    void HandleMessage(const packet_head* data);
protected:
    void HandleRegister(RegisterResult* data);
    void HandleLogin(LoginResult* data);
    void HandleError(const packet_head* data);
    void HandleLoadLogin(LoginReply* data);

private:
    QLineEdit* accountEdit_;
    QLineEdit* passwordEdit_;
    QPushButton* loginBtn_;

private:
    QString ip_;
    uint16_t port_;
    bool isLogin_ = false;
    bool isConnected_ = false;
    QTcpSocket* socket_ = nullptr;
};

uint64_t GetTimeStamp();

#endif //LOGINWGT_H